#pragma once

#include <fcntl.h>
#include <fstream>
#include <iostream>
#include <linux/videodev2.h>
#include <malloc.h>
#include <poll.h>
#include <sstream>
#include <string.h>
#include <list>


typedef struct YUVDataSt {
    unsigned char *data;
    int len;
    YUVDataSt()
    {
        data = NULL;
        len = 0;
    };
    ~YUVDataSt()
    {
        if (data) {
            free(data);
            data = NULL;
        }
    };
} YUVData;

class JetsonEncListener 
{
public:
    virtual void OnJetsonEncData(unsigned char *data, int data_len) = 0;
};

class JetsonEncAPI
{
public:
	static JetsonEncAPI* CreateJetsonEnc(int width, int height, int video_fps);
	virtual void Init(std::string strPixfmt,int width, int height, int video_fps)=0;
    virtual  ~JetsonEncAPI(){};
    virtual  void SetEncCallBack(JetsonEncListener *call_func)=0;
    virtual void UnSetEncCallBack()=0;
    virtual void AddFrame(unsigned char *data, int len)=0;
    virtual int GetQueueSize()=0;

};


class JetsonDecListener 
{
public:
    virtual void OnJetsonDecData(unsigned char *data, int data_len, uint64_t timestamp) = 0;
};

class JetsonDecAPI
{
public:
    // decoder_pixfmt:V4L2_PIX_FMT_H264 V4L2_PIX_FMT_H265
    static JetsonDecAPI* CreateJetsonDec(uint32_t decoder_pixfmt, int width = -1, int height = -1, unsigned char *buffer = NULL);
	    static JetsonDecAPI* CreateJetsonDec(std::string decoder_pixfmt, int width = -1, int height = -1, unsigned char *buffer = NULL);
    virtual ~JetsonDecAPI(){};
    virtual void SetDecCallBack(JetsonDecListener  *call_func)=0;
    virtual void UnSetDecCallBack()=0;
    virtual void AddEsData(unsigned char *data, int len, uint64_t time_data)=0;
    virtual int GetQueueSize()=0;
};